//
//  YSLWebViewController.m
//  used
//
//  Created by lanou on 16/7/16.
//  Copyright © 2016年 王凯. All rights reserved.
//

#import "YSLWebViewController.h"

#pragma clang diagnostic ignored "-Wincompatible-pointer-types"

@interface YSLWebViewController ()<UIWebViewDelegate>
@property (nonatomic, strong)UIWebView *webView;

@property (nonatomic, strong)NSString *html;
/** 数据源 */
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation YSLWebViewController

- (NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

- (UIWebView *)webView{
    
    if (!_webView) {
        _webView = [[UIWebView alloc] initWithFrame: self.view.frame];
        _webView.delegate = self;
        _webView.scrollView.bounces = NO;
        _webView.scrollView.bouncesZoom = NO;
    }
    return _webView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview: self.webView];


    //捏合手势
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];
    [self.webView addGestureRecognizer:pinch];

    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.imageArray]]];

}

#pragma mark ---webViewDelegate-----
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString *js = @"function imgAutoFit() { \
    var imgs = document.getElementsByTagName('img'); \
    for (var i = 0; i < imgs.length; ++i) {\
    var img = imgs[i];   \
    img.style.maxWidth = %f;   \
    } \
    }";
    js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
    
    [webView stringByEvaluatingJavaScriptFromString:js];
    [webView stringByEvaluatingJavaScriptFromString:@"imgAutoFit()"];
}

#pragma mark - 手势
- (void)pinchAction:(UIPinchGestureRecognizer *)pinch {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
